package com.rpframework.core.utils;

import java.util.List;

import freemarker.template.SimpleScalar;
import freemarker.template.TemplateMethodModel;
import freemarker.template.TemplateModelException;

/**
 * 
 * @Desc freemarker中使用的方法，根据传入的参数返回相应的值
 * @author xujp1
 * @version Revision: 1.00 Date: May 9, 2012
 */
@SuppressWarnings("deprecation")
public class GetUserAge implements TemplateMethodModel {

	@SuppressWarnings("unchecked")
	@Override
	public Object exec(List args) throws TemplateModelException {
		if (args.size() != 1) {
			throw new TemplateModelException("Wrong arguments!");
		}
		int age = 0;
		if ("xujp1".equalsIgnoreCase((String) args.get(0)))
			age = 25;
		else
			age = 24;
		return new SimpleScalar(String.valueOf(age));
	}
}